.TH std::basic_ostream 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_ostream \- std::basic_ostream

.SH Synopsis
   Defined in header <ostream>
   template<

       class CharT,
       class Traits = std::char_traits<CharT>

   > class basic_ostream : virtual public std::basic_ios<CharT, Traits>

   The class template basic_ostream provides support for high level output operations
   on character streams. The supported operations include formatted output (e.g.
   integer values) and unformatted output (e.g. raw characters and character arrays).
   This functionality is implemented in terms of the interface provided by the
   basic_streambuf class, accessed through the basic_ios base class. In typical
   implementations, basic_ostream has no non-inherited data members.

   std-basic ostream-inheritance.svg

                                   Inheritance diagram

   Several typedefs for common character types are provided:

   Defined in header <ostream>
   Type          Definition
   std::ostream  std::basic_ostream<char>
   std::wostream std::basic_ostream<wchar_t>

.SH Global objects

   Six global basic_ostream objects are provided by the standard library:

   Defined in header <iostream>
   cout  writes to the standard C output stream stdout
   wcout (global object)
   cerr  writes to the standard C error stream stderr, unbuffered
   wcerr (global object)
   clog  writes to the standard C error stream stderr
   wclog (global object)

.SH Member types

   Member type Definition
   char_type   CharT
   traits_type Traits; the program is ill-formed if Traits::char_type is not
               CharT.
   int_type    Traits::int_type
   pos_type    Traits::pos_type
   off_type    Traits::off_type

.SH Member functions

   constructor   constructs the object
                 \fI(public member function)\fP
   destructor    destructs the object
   \fB[virtual]\fP     \fI(virtual public member function)\fP
   operator=     move-assigns from another basic_ostream
   \fI(C++11)\fP       \fI(protected member function)\fP
.SH Formatted output
   operator<<    inserts formatted data
                 \fI(public member function)\fP
.SH Unformatted output
   put           inserts a character
                 \fI(public member function)\fP
   write         inserts blocks of characters
                 \fI(public member function)\fP
.SH Positioning
   tellp         returns the output position indicator
                 \fI(public member function)\fP
   seekp         sets the output position indicator
                 \fI(public member function)\fP
.SH Miscellaneous
   flush         synchronizes with the underlying storage device
                 \fI(public member function)\fP
   swap          swaps stream objects, except for the associated buffer
   \fI(C++11)\fP       \fI(protected member function)\fP

.SH Member classes

   sentry implements basic logic for preparation of the stream for output operations
          \fI(public member class)\fP

.SH Non-member functions

   operator<<(std::basic_ostream)  inserts character data or insert into rvalue stream
                                   \fI(function template)\fP
   print(std::ostream)             outputs formatted representation of the arguments
   (C++23)                         \fI(function template)\fP
   println(std::ostream)           outputs formatted representation of the arguments
   (C++23)                         with appended '\\n'
                                   \fI(function template)\fP
   vprint_unicode(std::ostream)    performs Unicode aware output using type-erased
   (C++23)                         argument representation
                                   \fI(function)\fP
   vprint_nonunicode(std::ostream) outputs character data using type-erased argument
   (C++23)                         representation
                                   \fI(function)\fP

Inherited from std::basic_ios

.SH Member types

   Member type Definition
   char_type   CharT
   traits_type Traits
   int_type    Traits::int_type
   pos_type    Traits::pos_type
   off_type    Traits::off_type

.SH Member functions

.SH State functions
   good          checks if no error has occurred i.e. I/O operations are available
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   eof           checks if end-of-file has been reached
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   fail          checks if an error has occurred
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   bad           checks if a non-recoverable error has occurred
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   operator!     checks if an error has occurred (synonym of fail())
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   operator bool checks if no error has occurred (synonym of !fail())
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   rdstate       returns state flags
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   setstate      sets state flags
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   clear         modifies state flags
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
.SH Formatting
   copyfmt       copies formatting information
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   fill          manages the fill character
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
.SH Miscellaneous
   exceptions    manages exception mask
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   imbue         sets the locale
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   rdbuf         manages associated stream buffer
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   tie           manages tied stream
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   narrow        narrows characters
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP
   widen         widens characters
                 \fI(public member function of std::basic_ios<CharT,Traits>)\fP

Inherited from std::ios_base

.SH Member functions

.SH Formatting
   flags             manages format flags
                     \fI(public member function of std::ios_base)\fP
   setf              sets specific format flag
                     \fI(public member function of std::ios_base)\fP
   unsetf            clears specific format flag
                     \fI(public member function of std::ios_base)\fP
   precision         manages decimal precision of floating point operations
                     \fI(public member function of std::ios_base)\fP
   width             manages field width
                     \fI(public member function of std::ios_base)\fP
.SH Locales
   imbue             sets locale
                     \fI(public member function of std::ios_base)\fP
   getloc            returns current locale
                     \fI(public member function of std::ios_base)\fP
.SH Internal extensible array
   xalloc            returns a program-wide unique integer that is safe to use as index
   \fB[static]\fP          to pword() and iword()
                     \fI(public static member function of std::ios_base)\fP
                     resizes the private storage if necessary and access to the long
   iword             element at the given index
                     \fI(public member function of std::ios_base)\fP
                     resizes the private storage if necessary and access to the void*
   pword             element at the given index
                     \fI(public member function of std::ios_base)\fP
.SH Miscellaneous
   register_callback registers event callback function
                     \fI(public member function of std::ios_base)\fP
   sync_with_stdio   sets whether C++ and C I/O libraries are interoperable
   \fB[static]\fP          \fI(public static member function of std::ios_base)\fP
.SH Member classes
   failure           stream exception
                     \fI(public member class of std::ios_base)\fP
   Init              initializes standard stream objects
                     \fI(public member class of std::ios_base)\fP

.SH Member types and constants
   Type           Explanation
                  stream open mode type

                  The following constants are also defined:

                  Constant          Explanation
                  app               seek to the end of stream before each write
                  binary            open in binary mode
   openmode       in                open for reading
                  out               open for writing
                  trunc             discard the contents of the stream when
                                    opening
                  ate               seek to the end of stream immediately after
                                    open
                  noreplace (C++23) open in exclusive mode

                  \fI(typedef)\fP
                  formatting flags type

                  The following constants are also defined:

                  Constant    Explanation
                  dec         use decimal base for integer I/O: see std::dec
                  oct         use octal base for integer I/O: see std::oct
                  hex         use hexadecimal base for integer I/O: see std::hex
                  basefield   dec | oct | hex. Useful for masking operations
                  left        left adjustment (adds fill characters to the right): see
                              std::left
                  right       right adjustment (adds fill characters to the left): see
                              std::right
                  internal    internal adjustment (adds fill characters to the internal
                              designated point): see std::internal
                  adjustfield left | right | internal. Useful for masking
                              operations
                              generate floating point types using scientific notation,
                  scientific  or hex notation if combined with fixed: see
                              std::scientific
   fmtflags                   generate floating point types using fixed notation, or
                  fixed       hex notation if combined with scientific: see
                              std::fixed
                  floatfield  scientific | fixed. Useful for masking operations
                  boolalpha   insert and extract bool type in alphanumeric format: see
                              std::boolalpha
                              generate a prefix indicating the numeric base for integer
                  showbase    output, require the currency indicator in monetary I/O:
                              see std::showbase
                  showpoint   generate a decimal-point character unconditionally for
                              floating-point number output: see std::showpoint
                  showpos     generate a + character for non-negative numeric output:
                              see std::showpos
                  skipws      skip leading whitespace before certain input operations:
                              see std::skipws
                  unitbuf     flush the output after each output operation: see
                              std::unitbuf
                              replace certain lowercase letters with their uppercase
                  uppercase   equivalents in certain output operations: see
                              std::uppercase

                  \fI(typedef)\fP
                  state of the stream type

                  The following constants are also defined:

                  Constant Explanation
   iostate        goodbit  no error
                  badbit   irrecoverable stream error
                  failbit  input/output operation failed (formatting or extraction
                           error)
                  eofbit   associated input sequence has reached end-of-file

                  \fI(typedef)\fP
                  seeking direction type

                  The following constants are also defined:

   seekdir        Constant Explanation
                  beg      the beginning of a stream
                  end      the ending of a stream
                  cur      the current position of stream position indicator

                  \fI(typedef)\fP
   event          specifies event type
                  \fI(enum)\fP
   event_callback callback function type
                  \fI(typedef)\fP
